package com.neusoft.demo5;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

public class Master {

    public void cure(Pet pet) { //参数传递父类型 Pet pet = new Dog();
        if(pet.getHealth() < 50) {
            pet.toHospital();
        }
    }

    public void play(Pet pet) {
        //float f = (float) 3.14; 基本数据类型的强制转换
        //        Dog dog = (Dog) pet;
        //        dog.game();
        //
        //        Penguin penguin = (Penguin) pet;
        //        penguin.swimming();
        if(pet instanceof Dog) {
            Dog dog = (Dog) pet;
            dog.game();
        }else if(pet instanceof Penguin) {
            Penguin penguin = (Penguin) pet;
            penguin.swimming();
        }
    }


    public static void main(String[] args) {
        Master master = new Master();

        Pet pet = new Dog();  //注意：抽象类不能被实例化
        pet.setName("大黄");
        pet.setHealth(30);
        pet.setLove(100);

        master.cure(pet);
        master.play(pet);

        pet = new Penguin();
        pet.setName("QQ");
        pet.setHealth(20);
        pet.setLove(100);

        master.cure(pet);
        master.play(pet);

//        Reader reader =new FileReader("");
//        BufferedReader bufferedReader = new BufferedReader(reader);
    }
}
